package com.qo.qsdk.ui.base.floater;

import android.app.Activity;
import android.app.Dialog;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.qo.qsdk.utils.DynamicUtils;

/**
 * @author Anmi on 2018/4/20.
 */

public class DialogUtil {

    //web对话框
    public static Dialog createWebDialog(Activity act, View layout) {
        Dialog intputDialog = new Dialog(act, DynamicUtils.style(act, "YYSDKAlertDialogStyle"));
        intputDialog.setCanceledOnTouchOutside(false);
        intputDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        intputDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        intputDialog.getWindow().setGravity(Gravity.CENTER);
        intputDialog.show();

        WindowManager.LayoutParams lp = intputDialog.getWindow().getAttributes();

        int screenHeightPixels =  act.getResources().getDisplayMetrics().heightPixels;
        int screenWidthPixels =  act.getResources().getDisplayMetrics().widthPixels;
        int width = 0;
        int height = 0;

        if (act.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // 横屏
            width = (int) (screenWidthPixels * 0.7);
            height = (int) (screenHeightPixels * 0.85);
        } else if (act.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            // 竖屏
            width = (int) (screenWidthPixels * 0.9);
            height = (int) (screenHeightPixels * 0.7);
        }
        lp.width = width; // 设置宽度
        lp.height = height;

        intputDialog.getWindow().setAttributes(lp);
        intputDialog.getWindow().setContentView(layout);

        return intputDialog;
    }

}
